<template>
	<view>
		<view><u-toast ref="uToast" /></view>
		<view class="work_top box_radius">
			<view class="box box-pack-between box-align-center">
				<view class="left" style="width: 85%;" >
					<image :src="app.app_img" class="work_top clockImg"></image>
					<view style="padding-top: 40rpx; font-weight: bolder;">{{app.app_name}}</view>
					<view style="color: #bfbfbf; padding-top: 15rpx;">{{app.app_size}}M</view>
				</view>
				<view class="right">
					<u-button @click="unInstallApp">卸载</u-button>
				</view>
			</view>
			<view class="optionClass">
				<text class="optionClass text">是否允许联网</text>
				<u-switch style="float: right;" v-model="app.is_network" @change="((val)=>{changeSwitch(val,'is_network')})"></u-switch>
			</view>
			<view class="optionClass" v-if="false">
				<text class="optionClass text">桌面显示图标</text>
				<u-switch style="float: right;" v-model="app.is_show"></u-switch>
			</view>
			<view class="optionClass">
				<text class="optionClass text">是否允许更新</text>
				<u-switch style="float: right;" v-model="app.is_upgrade" @change="((val)=>{changeSwitch(val,'is_upgrade')})"></u-switch>
			</view>
			<view class="optionClass" v-if="false">
				<text class="optionClass text">应用锁定</text>
				<u-switch style="float: right;" v-model="app.is_lock"></u-switch>
			</view>
			<view class="optionClass">
				<text class="optionClass text">是否允许滑动</text>
				<u-switch style="float: right;" v-model="app.is_slide" @change="((val)=>{changeSwitch(val,'is_slide')})"></u-switch>
			</view>
			<view class="optionClass" v-if="false">
				<text class="optionClass text">是否允许自启</text>
				<u-switch style="float: right;" v-model="app.is_auto" @change="((val)=>{changeSwitch(val,'is_auto')})"></u-switch>
			</view>
		</view>
	</view>
	
</template>

<script>
	import {
		editAppInstall,
		queryIdApp,
		appUninstall
	} from '@/api/userHome.js'
	export default {
		data() {
			return {
				app: {
					app_img: '',
					app_name: '',
					app_size: 0,
					app_id: 0,
					is_network: false,
					is_show: false,
					is_upgrade: false,
					is_lock: false,
					is_auto: false,
					is_slide: false,
					log_id: 0
				},
				
			}
		},
		onLoad(option) {
			const item = JSON.parse(decodeURIComponent(option.item));
			this.log_id = item.id
			if (item.app_id) {
				this.queryIdAppControl(item.app_id)
			}
		},
		methods: {
			changeSwitch(val, name) {
				editAppInstall({
					id: this.app.app_id,
					name: name,
					value: Number(val),
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
				}).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
						icon: false
					})
					
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						type: 'error',
						icon: false
					})
				})
			},
			
			queryIdAppControl(app_id) {
				queryIdApp({
					id: app_id
				}).then(res => {
					this.app = res.data
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						type: 'error',
						icon: false
					})
				})
				
			},
			unInstallApp() {
				let param = {
					app_id: this.app.app_id,
					id: uni.getStorageSync("snId"),
					userId: uni.getStorageSync("userId"),
					logId: this.log_id
				}
				appUninstall(param).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
						icon: false
					})
					setTimeout(()=> {
						uni.navigateBack({delta:1})
					}, 500)
					
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						type: 'error',
						icon: false
					})
				})
				
			}
			
		}
	}
</script>

<style lang="scss">
	.work_top {
		background-color: #FFFFFF;
		padding: 30rpx;
		margin: 30rpx;
		.clockImg {
			    height: 150rpx;
			    width: 150rpx;
			    float: left;
			    padding: 0rpx;
			    padding-right: 10rpx;
			    margin: 0rpx;

		}
	}
	.optionClass {
		    height: 100rpx;
		    padding: 20rpx;
		    margin-top: 40rpx;
			.text {
				font-size: 31rpx;
				word-spacing: 2rpx;
			}
	}
</style>